/**
 * 地图数据源
 */
import {FreeMap} from "../map/FreeMap";
import {Layer} from "../layer/Layer";

export abstract class Source {
    public sourceId: string;

    public layers: Array<Layer> = [];

    protected map: FreeMap;

    public state: SourceState = SourceState.READY;

    constructor(sourceId: string) {
        this.sourceId = sourceId;
    }

    public addTo(map: FreeMap) {
        this.map = map;
    }

    /**
     * 关联图层
     * @param {Layer} layer
     */
    public connectLayer(layer: Layer) {
        this.layers.push(layer);
    }

    public pushDataToLayer(data: any) {
        this.layers.forEach(layer => {
            layer.onSourceDataChange(data)
        })
    }
}

export enum SourceState {
    READY = "ready",
    LOADING = "loading",
    LOADED = "loaded",
    ERROR = "error"
}
